﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lepton_Practical_MVVM_6_1.Services {
    internal static class MenuItemExtension {
        internal static Models.MyMenuItem Search(this Models.MyMenuItem node, Predicate<Models.MyMenuItem> match) {
            Queue<Models.MyMenuItem> queue = new Queue<Models.MyMenuItem>();
            queue.Enqueue(node);
            while (queue.Count > 0) {
                Models.MyMenuItem thisNode = queue.Dequeue();
                if (match(thisNode))
                    return thisNode;
                foreach (Models.MyMenuItem child in thisNode.Child)
                    queue.Enqueue(child);
            }
            return null;
        }
    }
}